package jm.mq.workers;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import jm.mq.utils.RabbitMQUtils;

/**
 * @Description 工作线程01
 * @date 2022/3/5 10:07
 */
public class Worker1 {
    // 指定队列名称
    private static final String QUEUE_NAME = "work_queue";

    public static void main(String[] args) throws Exception {

        // 获取信道
        Channel channel = RabbitMQUtils.getChannel();

        // 声明：接收消息回调
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("工作线程01："+ new String(message.getBody()));
        };

        // 声明：取消消费回调
        CancelCallback cancelCallback = consumerTag -> {
            System.out.println("工作线程01取消接收："+consumerTag);
        };

        System.out.println("工作线程01启动完成......");

        channel.basicConsume(QUEUE_NAME,false,deliverCallback,cancelCallback);
    }
}
